/******************************************************************
 *  MRRM's write back unit                                        *
 *                                                                *
 *  This file is part of the MRRM project                         *
 *  <http://mrrm.googlecode.com/>                                 *
 *                                                                *
 *  Author(s):                                                    *
 *    -  Yuan Pengfei <coolypf@opencores.org>                     *
 *                                                                *
 ******************************************************************
 *                                                                *
 *  Copyright (C) 2010 AUTHORS                                    *
 *                                                                *
 *  This source file may be used and distributed without          *
 *  restriction provided that this copyright statement is not     *
 *  removed from the file and that any derivative work contains   *
 *  the original copyright notice and the associated disclaimer.  *
 *                                                                *
 *  MRRM is free software: you can redistribute it and/or modify  *
 *  it under the terms of the GNU General Public License as       *
 *  published by the Free Software Foundation, either version 3   *
 *  of the License, or (at your option) any later version.        *
 *                                                                *
 *  MRRM is distributed in the hope that it will be useful, but   *
 *  WITHOUT ANY WARRANTY; without even the implied warranty of    *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  *
 *  GNU General Public License for more details.                  *
 *                                                                *
 *  You should have received a copy of the GNU General Public     *
 *  License along with MRRM. If not, see                          *
 *  <http://www.gnu.org/licenses/>.                               *
 *                                                                *
 ******************************************************************/

`include "global.v"

module mrrm_wb(
	// RF interface
	addrx, addry, datax, datay, wrx, wry,
	// WB interface
	W_itype, W_valx, W_valy, W_valm,
	W_dstx, W_dsty, W_wrx, W_wry
	);

parameter aw = `REGFILE_ADDR_WIDTH;
parameter mw = `MEMORY_ADDR_WIDTH;
parameter ow = `OPERAND_WIDTH;

// Interfaces
// Register file
output [aw-1:0] addrx;
output [aw-1:0] addry;
output [ow-1:0] datax;
output [ow-1:0] datay;
output wrx;
output wry;

// Write back
input [2:1] W_itype;
input [ow-1:0] W_valx;
input [ow-1:0] W_valy;
input [ow-1:0] W_valm;
input [aw-1:0] W_dstx;
input [aw-1:0] W_dsty;
input W_wrx;
input W_wry;

// Register file access
assign addrx = W_dstx;
assign addry = W_dsty;
assign datax = (W_itype[2:1] == 2'b01) ? W_valm : W_valx;
assign datay = W_valy;
assign wrx = W_wrx;
assign wry = W_wry;

endmodule
